package mo.org.cm309.shoppingcart.service;

import java.util.ArrayList;
import java.util.List;

import mo.org.cm309.shoppingcart.dao.RoleDAO;
import mo.org.cm309.shoppingcart.entity.Role;


public class RoleService {
	private List<Role> roles;
	private static RoleService rService = new RoleService();
	
	public RoleService() {
		roles = RoleDAO.getInstance().findAll();
	}

	
	public static RoleService getrService() {
		return rService;
	}

	public String getNameById(long id){
		for (int i=0; i<roles.size(); i++){
			if (roles.get(i).getId()==id){
				return roles.get(i).getName();
			}
		}
		return "";
	}
	
	public long getIdByName(String name){
		for (int i=0; i<roles.size(); i++){
			if (roles.get(i).getName().equals(name)){
				return roles.get(i).getId();
			}
		}
		return 0;
	}
	
	
}
